package com.jxin.mall.config.exception;

import com.jxin.mall.config.parent.BaseService;
import com.jxin.mall.entity.entity.GlobalRsp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常
 * @author 蔡佳新
 * @version 1.0
 * @since jdk 1.8
 */
@ControllerAdvice
@Slf4j
public class GlobalException extends BaseService {
    /**全局异常消息模板*/
    private static final String GLOBAL_ERR_TEMP = "[全局捕获异常],发生通用全局异常,error:{}";

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public GlobalRsp exceptionHandler(Exception e) {
        log.error(GLOBAL_ERR_TEMP, e.getMessage(), e);
        return createFaild();
    }
}
